
//  ZHTableHeadView.m
//  LoveFreshBee
//
//  Created by brice Mac on 2016/10/15.
//  Copyright © 2016年 王忠迪. All rights reserved.
//

#define kHeaderW self.bounds.size.width
#define kHeaderH self.bounds.size.height

#import "ZHTableHeadView.h"
#import "ZHButton.h"
#import "ZHBaseViewController.h"
#import "MyOrderViewController.h"

@interface ZHTableHeadView ()

@property(nonatomic,weak)UIButton *orderBtn;

@property(nonatomic,weak)UIButton *couponBtn;

@property(nonatomic,weak)UIButton *messageBtn;

@end

@implementation ZHTableHeadView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        //设置背景色为白色
        self.backgroundColor = [UIColor whiteColor];
        [self setupTableHeaderView];
    }
    return self;
}

- (void)setupTableHeaderView {
    
    //计算button的宽
    CGFloat kBtnW = kHeaderW / 3;
    
    //我的订单
    BACustomButton *orderBtn = [[BACustomButton alloc] initWitAligenmentStatus:BAAligenmentStatusTop];
    _orderBtn = orderBtn;
    [orderBtn setImage:[UIImage imageNamed:@"v2_my_order_icon"] forState:UIControlStateNormal];
    [orderBtn setTitle:@"我的订单" forState:UIControlStateNormal];
    [orderBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    orderBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    //第一个btn的frame
    orderBtn.frame = CGRectMake(0, 0, kBtnW, kHeaderH);
    [self addSubview:orderBtn];
    //订单页面
    [orderBtn addTarget:self action:@selector(toMyOrderViewController) forControlEvents:UIControlEventTouchUpInside];
    
    //优惠券
    BACustomButton *couponBtn = [[BACustomButton alloc] initWitAligenmentStatus:BAAligenmentStatusTop];
    _couponBtn = couponBtn;
    [couponBtn setImage:[UIImage imageNamed:@"v2_my_coupon_icon"] forState:UIControlStateNormal];
    [couponBtn setTitle:@"优惠券" forState:UIControlStateNormal];
    [couponBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    couponBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    //第二个btn的frame
    couponBtn.frame = CGRectMake(kBtnW, 0, kBtnW, kHeaderH);
    [self addSubview:couponBtn];

#warning - 暂时没改
    [couponBtn addTarget:self action:@selector(toMyOrderViewController) forControlEvents:UIControlEventTouchUpInside];
    
    //我的消息
    BACustomButton *messageBtn = [[BACustomButton alloc] initWitAligenmentStatus:BAAligenmentStatusTop];
    _messageBtn = messageBtn;
    [messageBtn setImage:[UIImage imageNamed:@"v2_my_message_icon"] forState:UIControlStateNormal];
    [messageBtn setTitle:@"我的消息" forState:UIControlStateNormal];
    [messageBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    messageBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    //第三个btn的frame
    messageBtn.frame = CGRectMake(2*kBtnW, 0, kBtnW, kHeaderH);
    [self addSubview:messageBtn];

#warning - 暂时没改
    [messageBtn addTarget:self action:@selector(toMyOrderViewController) forControlEvents:UIControlEventTouchUpInside];
    
    //按钮中间的分隔线1
    UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(kBtnW, kHeaderH*0.2, 1, kHeaderH*0.6)];
    line1.backgroundColor = [UIColor grayColor];
    line1.alpha = 0.3;
    [self addSubview:line1];
    
    //按钮中间的分隔线2
    UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(2*kBtnW, kHeaderH*0.2, 1, kHeaderH*0.6)];
    line2.backgroundColor = [UIColor grayColor];
    line2.alpha = 0.3;
    [self addSubview:line2];
}

- (void)toMyOrderViewController {
    MyOrderViewController *order = [[MyOrderViewController alloc]init];
    
    [[self viewController].navigationController pushViewController:order animated:YES];
}

- (void)toMyCouponViewController {
    
}

- (void)toMyMessageViewController {
    
}


/**
    获取当前 view 的superView对应的控制器

 @return vc
 */
- (UIViewController *)viewController
{
    //获取当前view的superView对应的控制器
    UIResponder *next = [self nextResponder];
    do {
        if ([next isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)next;
        }
        next = [next nextResponder];
    } while (next != nil);
    return nil;
    
}

@end
